package com.graduation.lastproject.util.stringUtil;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

public class trimFirstAndLastChar {
    //去掉首尾指定字符串
    public static  String trim(String source,char element){

        boolean beginIndexFlag = true;

        boolean endIndexFlag = true;

        do{

            int beginIndex = source.indexOf(element) == 0 ? 1 : 0;

            int endIndex = source.lastIndexOf(element) + 1 == source.length() ? source.lastIndexOf(element) : source.length();

            source = source.substring(beginIndex, endIndex);

            beginIndexFlag = (source.indexOf(element) == 0);

            endIndexFlag = (source.lastIndexOf(element) + 1 == source.length());

        } while (beginIndexFlag || endIndexFlag);

        return source;
    }
    //生成唯一订单号  同时下单人数不超过一万应该不会重复 傻了哦
    public static String onlyout_trade_no(){
            String date=new SimpleDateFormat("yyyyMMdd").format(new Date());
            String seconds=new SimpleDateFormat("HHmmss").format(new Date());
            System.out.println("时间戳"+new Date().getTime());
            return date+"00001000"+getTwo()+"00"+seconds+getTwo();

    }
    /**
     * 产生随机的2位数
     * @return
     */
    public static String getTwo(){
        Random rad=new Random();

        String result  = rad.nextInt(100) +"";   /*0-100之间*/

        if(result.length()==1){
            result = "0" + result;
        }
        return result;
    }
}
